using System;
using System.Windows.Forms;

using OpenEdge.Utility;


namespace OpenEdge.DatabaseEngineering.Import
{
	public class Application : IDisposable
	{

		private OptionsForm optionsForm;
		private Importer	importer;
		private LogWriter	logWriter;

		public Application(EA.Repository eaRepository)
		{

			importer		= new Importer(eaRepository);
			optionsForm		= new OptionsForm();
			logWriter		= new LogWriter();

			optionsForm.OpenLogWriter	+= new OptionsForm.LogWriterRequest(this.openLogWriter);
			optionsForm.Import			+= new OptionsForm.ImportRequest(this.importer.import);
			optionsForm.CloseLogWriter	+= new OptionsForm.CloseLogWriterRequest(this.closeLogWriter);
			
			importer.LogWriteLine		+= new Importer.LogRequest(this.logWriter.WriteLineHandler);
			importer.LogWriteLine		+= new Importer.LogRequest(this.optionsForm.logWriteLineHandler);

			importer.progressLength	    += new Importer.ProgressRequest(this.optionsForm.progressLengthHandler);
			importer.progressNumChars   += new Importer.ProgressRequest(this.optionsForm.progressRequestHandler);
			importer.importEnd			+= new Importer.EndRequest(this.optionsForm.progressEndHandler);

		}


		public void showOptionsForm() 
		{
			
			this.optionsForm.Show();

		}
		
		private void openLogWriter(String filePath)
		{
			this.logWriter.Open(filePath);
		}

		private void closeLogWriter()
		{
			this.logWriter.Close();
		}

		public void createSchemaRelationships()
		{
			this.importer.createSchemaRelationships2();
		}

		public void createSchemaDiagram() 
		{
			this.importer.createSchemaDiagram2();
		}

		#region IDisposable Members

		public void Dispose()
		{
			optionsForm.Dispose();
			optionsForm = null;

			importer.Dispose();
			importer = null;
		}

		#endregion
	}
}
